1138B - Circus - CodeForces Solution


brute force greedy math strings *1800

Please click on ads to support us..

C++ Code:

/*
Problem: 1138B
Date: 22-01-2024 05:16 AM
*/


#include <iostream>
#include <set>
#include <vector>
#include <cmath>

using namespace std;

int n;
string c, a;
vector<int> s[2][2];
vector<int> f;

int main() {
	cin >> n >> c >> a;
	for(int i = 0; i < n; i++) {
		s[c[i] - '0'][a[i] - '0'].push_back(i + 1);
	}
	int na = s[0][0].size(), nb = s[0][1].size(), nc = s[1][0].size(), nd = s[1][1].size();
	for(int a = 0; a <= na; a++) {
		for(int b = 0; b <= nb; b++) {
			int d = a - n/2 + nb + nd;
			int c = nb + nd - b - 2 * d;
			if(0 <= c && c <= nc && 0 <= d && d <= nd) {
				for(int i = 0; i < a; i++) {
					cout << s[0][0][i] << " ";
				}for(int i = 0; i < b; i++) {
					cout << s[0][1][i] << " ";
				}for(int i = 0; i < c; i++) {
					cout << s[1][0][i] << " ";
				}for(int i = 0; i < d; i++) {
					cout << s[1][1][i] << " ";
				}
				return 0;
			}
		}
	}
	cout << -1 << endl;
}


Comments

Submit
0 Comments
More Questions

1409B - Minimum Product
723B - Text Document Analysis
1471C - Strange Birthday Party
1199A - City Day
1334A - Level Statistics
67B - Restoration of the Permutation
1734A - Select Three Sticks
1734B - Bright Nice Brilliant
357B - Flag Day
937A - Olympiad
1075A - The King's Race
1734C - Removing Smallest Multiples
1004C - Sonya and Robots
922A - Cloning Toys
817A - Treasure Hunt
1136B - Nastya Is Playing Computer Games
1388A - Captain Flint and Crew Recruitment
592B - The Monster and the Squirrel
1081A - Definite Game
721C - Journey
1400A - String Similarity
1734E - Rectangular Congruence
1312D - Count the Arrays
424C - Magic Formulas
1730C - Minimum Notation
1730B - Meeting on the Line
1730A - Planets
302B - Eugeny and Play List
1730D - Prefixes and Suffixes
1515C - Phoenix and Towers